<include file="../header" />
<body>
<div class="wraper">
    <div class="load">
        <img class="load-bee" src="/assets/repairnew/images/load-bee.png"/>
    </div>
    <div class="top">
        <p class="clearfix">
            <a href="javascript:history.back(-1)" class="iconfont icon-zuo fl-left"></a>
            <span class="fl-left"><if condition="$applyType eq 2">物料返还<elseif condition="$applyType eq 3" />废料返还</if></span>
            <a href="#" class="fl-left"></a>
        </p>
    </div>

    <div class="clearfix" id="materialData">
        <volist name="data" id="vo">
            <div class="list tb-mode">
                <div class="tb-cell lineheight15"><p>{BEESCRM:$vo.material_name}</p></div>
                <div class="tb-cell material_num">
                    <div class="quantity pull-right">
                        <span class="change-num-btn btn_minus fl-left"  data-material_id="{BEESCRM:$vo.material_id}">-</span>
                        <input type="number" value="0" readonly="readonly" class="buy-count fl-left">
                        <span class="change-num-btn btn_plus fl-left" data-max="{BEESCRM:$vo.number}"  data-material_id="{BEESCRM:$vo.material_id}">+</span>
                    </div>
                </div>
            </div>
        </volist>

    </div>
    <div class="marginb-50"></div>
    <div class="btn-box">
        <a href="javascript:void(0)" class="btn full-btn addorder fl-left">确认返还</a>
    </div>
</div>
<include file="../commonJS" />
<script type="text/javascript" src="/assets/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.fileupload.js"></script>
<script type="text/javascript" src="/assets/bower_components/upload/jquery.iframe-transport.js"></script>
<script type="text/javascript">
    $(function(){
        $(document).ready(function(){
            $(document).on('click','.btn_minus',function(){
                var value = $(this).next().val();
                if(value <= 1){
                    value = 0;
                    $(this).addClass('hide_right').siblings().addClass('hide_right');
                }else{
                    value--;
                }
                $(this).next().val(value);
            });

            $(document).on('click','.btn_plus',function(){
                var value = parseInt($(this).prev().val());
                if(value <= 0){
                    value = 1;
                    $(this).removeClass('hide_right').siblings().removeClass('hide_right');
                }else{
                    var max = parseInt($(this).data('max'));
                    if(value+1<=max){
                        value++;
                    }/*else{
                        $.alert('error','超过了申领数量');
                    }*/
                }
                $(this).prev().val(value);
            });
        });


        //物料返还提交
        $(document).on('click','.addorder',function(){
        var data = {};
           var submit_material = [];
           var num=0;//值
           var materialId = '';
           var totalNum = 0;//总数
           $('.material_num').each(function(){
                num = parseInt($(this).find('.buy-count').val());
                if(num>0){
                    materialId = $(this).find('.btn_minus').data('material_id');
                    submit_material.push(materialId+'-'+num);
                    totalNum+=num;
                }
           })
           
           if(totalNum==0){
             $.alert('error','至少选择一件物品');return false;
           }

           
           data.submit_material = submit_material.join(',');
           data.order_id = "{BEESCRM:$orderId}";
           data.apply_type = "{BEESCRM:$applyType}";

           $.ajax({
             url:"/repairnew/repairnewMaterial/doRevert/repairId/"+"{BEESCRM:$repairId}",
             type:"post",
             data:data,
             dataType:'json',
             success:function(res){
                if(res.status == 'S'){
                    $.alert('success',res.message);
                    setTimeout('location.href="/index.php?g=repairnew&m=repairnewReceive&a=index&repairId={BEESCRM:$repairId}&order_id={BEESCRM:$orderId}"',2000);
                }else{
                    $.alert('error',res.message);
                }
             }
           })


        })
    })
</script>
</body>
</html>
